package Main;

import java.awt.Color;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import Game_Start.Win;
import Mouse_key_Event.Key;
import Mouse_key_Event.eastbutton;
import player.Musics;

public class makeEastPanel {
	static eastbutton button4[];
	public static eastPanel panel;
	private  makeEastPanel()
	{
		
	}
	public static eastbutton getButton0Start()
	{
		return button4[0];
	}
	public static eastbutton getButton1Stop()
	{
		return button4[1];//暂停按钮
	}
	public static void setButton(eastPanel panel)
	{
		//System.out.println("set");
		makeEastPanel.panel=panel;
		panel.setFocusable(false);//防止东边的面板获取了键盘的焦点，导致键盘控制了按钮右不给主窗口焦点
		
		button4=new eastbutton[4];
		for(int i=0;i<button4.length;i++)
		{
			button4[i]=new eastbutton("");
			
			panel.add(button4[i]);
		}
		panel.setLayout(new GridLayout(4,1,20,20));
		
		button4[0].setText("重新游戏");
		button4[0].setLocation(0, 0);
		
		button4[0].addActionListener(new myListener());
		
		button4[1].setText("暂停游戏");
		button4[1].addActionListener(new myListener());
		button4[2].setText("音效");
		button4[2].addActionListener(new myListener());
		button4[3].setText("返回主菜单");
		button4[3].addActionListener(new myListener());
		
	}
}

class myListener implements ActionListener{

	
	public  void actionPerformed(ActionEvent e) {
		// TODO 自动生成的方法存根
		if(e.getActionCommand().equals("重新游戏"))
		{
			Main_Frame.snake.clear();
			Main_Frame.snake.Init();
			makeEastPanel.button4[1].setForeground(Color.red);//将暂停字变红
			Key.Stop=true;
		}else if(e.getActionCommand().equals("暂停游戏"))
		{
			Key.Stop=!Key.Stop;
			if(Key.Stop==true) makeEastPanel.button4[1].setForeground(Color.red);
			else makeEastPanel.button4[1].setForeground(Color.black);
			makeEastPanel.panel.repaint();
			Main_Frame.getpanel().repaint();
			
		}else if(e.getActionCommand().equals("音效"))
		{
			makeEastPanel.button4[2].setForeground
			(makeEastPanel.button4[2].getForeground()
					==Color.red?Color.black:Color.red);
			Musics.closeMusics=!Musics.closeMusics;//蛇的声音
		}else if(e.getActionCommand().equals("返回主菜单"))
		{
			Main_Frame.Close();
			FileIO.IO.OUT(Main_Frame.snake);
			Win.getFrame().setVisible(true);;
		}
		
	}
	
}
